const baseUrl = "https://api-hmugo-web.itheima.net/api/public/v1"
const request = function (options) {
  options.url = baseUrl + options.url
  return new Promise((resolve, reject) => {
    wx.request({
      ...options,
      timeout: 5000,
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}

// 封装导航栏api
const catitemsApi = {
  getCatitemsApi: function () {
    return request({
      url: "/home/catitems",
    })

  }
}
// 封装首页楼层api
const getFloordataApi = {
  getFloordataApi: function () {
    return request({
      url: "/home/floordata",
    })

  }
}
//封装分类api接口
const categoriesApi = {
  getCategories: function () {
    return request({
      url: "/categories",
    })

  }
}
//商品列表搜索封装api /goods/search
const shopSearchApi = {
  getshopSearchApi:function(data){
    return request({
      url:"/goods/search",
      method:"GET",
      data:data
    })
  }
}
const API = {
  // 封装导航栏api
  catitemsApi,
  // 封装首页楼层api
  getFloordataApi,
  //封装分类api接口
  categoriesApi,
  // 商品列表搜索封装api 
  shopSearchApi,
}
export default API